import configparser
import os

import pygame
from random import *

"""
游戏中的强化，包括:
- 超级子弹
- 全屏核弹
"""

def resder_config():
    conf = configparser.ConfigParser()
    curpath = os.path.dirname(os.path.realpath(__file__))
    path = os.path.join(curpath, '../config.ini')
    conf.read(path, encoding="utf-8")
    client_config = conf["client"]
    gameplay_config = conf["gameplay"]
    return client_config, gameplay_config


_, gameplay_config = resder_config()

#超级子弹
class BulletSupply(pygame.sprite.Sprite):
    def __init__(self, bg_size):
        super().__init__()
        self.image = pygame.image.load("./images/bullet_supply.png")
        self.rect = self.image.get_rect()
        self.width, self.height = bg_size[0], bg_size[1]
        self.rect.left = randint(0, self.width - self.rect.width)
        self.rect.top = -100
        self.speed = int(gameplay_config["suppy_speed"])
        self.active = False
        self.mask = pygame.mask.from_surface(self.image)

    def move(self):
        if self.rect.y < self.height:
            self.rect.y += self.speed
        else:
            self.active = False

    def reset(self):
        self.rect.x = randint(0, self.width - self.rect.width)
        self.rect.top = -100
        self.active = True


#核弹
class BombSupply(pygame.sprite.Sprite):
    def __init__(self, bg_size):
        super().__init__()
        self.image = pygame.image.load("./images/bomb_supply.png")
        self.rect = self.image.get_rect()
        self.width, self.height = bg_size[0], bg_size[1]
        self.rect.left = randint(0, self.width - self.rect.width)
        self.rect.top = -100
        self.speed = int(gameplay_config["suppy_speed"])
        self.active = False
        self.mask = pygame.mask.from_surface(self.image)

    def move(self):
        if self.rect.y < self.height:
            self.rect.y += self.speed
        else:
            self.active = False

    def reset(self):
        self.rect.x = randint(0, self.width - self.rect.width)
        self.rect.top = -100
        self.active = True
